package cc.mrbird.system.service.impl;

import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.UserRoselEnum;
import cc.mrbird.common.service.impl.BaseService;
import cc.mrbird.system.dao.DaliyMapper;
import cc.mrbird.system.dao.UserMapper;
import cc.mrbird.system.domain.*;
import cc.mrbird.system.service.DaliyService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service("daliyService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DaliyServiceImpl extends BaseService<Daliy> implements DaliyService {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    private static final Integer ONE_WEEK = 6;
    /**
     * 日报数据 sql 接口
     */
    @Autowired
    private DaliyMapper daliyMapper;

    /**
     * 日报接口
     */
    @Autowired
    private DaliyService daliyService;

    /**
     * 用户信息
     */
    @Autowired
    private UserMapper userMapper;


    /**
     * 日报信息
     *
     * @return
     */
    @Override
    public DaliyDTO daliyMessage() throws ParseException {
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //日期转换对象
        GregorianCalendar cal = new GregorianCalendar();
        //当天时间
        cal.setTime(sdf.parse(sdf.format(new Date())));
        //获取周数
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        //年
        int year = cal.get(Calendar.YEAR);
        //获取当天是周几
        char[] weekChar = new char[]{'日','一','二','三','四','五','六'};
        //这个月有多少个星期天
        int weekDayNum = weekDays();
        //当月有多少天
        int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //获取当月有多少天要打卡
        int day = actualMaximum - weekDayNum;
        //获取今天的日期前面有多少个星期日
        int dayNum = weekday();
        //根据当前的日期算出不用打卡天数
        //当天几号
        int date = new Date().getDate();
        //获取数据库个人信息打卡的时间
        //说明根据月份 用户id 查到计算未打卡天数 标记 星期天打开是无效的
        //获取签到日报天数星期天没有加上  当天打卡
        Integer daliyNum = daliyMapper.notToPlay(user.getUserId(), new Date().getMonth() + 1, year, date);
        //得到要打卡的天数=当天时间减去 -当天过去周日的天数
        int dateNum = date - dayNum;
        //打卡天数减去当天时间减去数据库要打卡的时间得到未打卡的天数
        int noDay = (dateNum - 1) - daliyNum;
        //联表查询查到要用户的角色跟组别
        User daliyMessage = userMapper.findUserProfile(user);
        DaliyDTO daliyDTO = new DaliyDTO();
        //用户id
        daliyDTO.setUserId(user.getUserId());
        //未打卡天数
        daliyDTO.setNotClockedIn(noDay);
        //用户名
        daliyDTO.setUserName(user.getUsername());
        //组别
        daliyDTO.setDeptName(daliyMessage.getDeptName());
        return daliyDTO;
    }

    /**
     * 添加日报
     *
     * @param daliyList                   日报的信息
     * @param executioneFficiency         百分效率
     * @param reasonsforeFficiencyFailure 效率不达标原因
     * @return
     */
    @Override
    public Boolean adliyAdd(List<DaliyDTO> daliyList, String executioneFficiency, String reasonsforeFficiencyFailure) {
        //日期
        Calendar cal = Calendar.getInstance();
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //先判断 根据当前user id 和 当前月份当月的几号 判断当天是否添加过日报
        Example example = new Example(Daliy.class);
        Example.Criteria criteria = example.createCriteria();
        //月份
        int month = new Date().getMonth() + 1;
        //几号
        int date = new Date().getDate();
        //年
        int year = cal.get(Calendar.YEAR);
        //获取当天是星期几
        String weekStr = getWeekStr(new Date());
        //用户id
        criteria.andEqualTo("userId", user.getUserId());
        //年
        criteria.andEqualTo("year", year);
        //月份
        criteria.andEqualTo("month", month);
        //几号
        criteria.andEqualTo("mark", date);
        int count = daliyMapper.selectCountByExample(example);
        //给对象批量转换
        ArrayList<Daliy> daliyArrayList = new ArrayList<>();
        //日报对象
        Daliy daliy = new Daliy();
        //日报dto对象
        DaliyDTO daliyDTO = new DaliyDTO();

        for (int i = 0; i < daliyList.size(); i++) {
            daliyDTO = daliyList.get(i);
            daliy = new Daliy();
            //年份
            daliyDTO.setYear(year);
            //用户id
            daliyDTO.setUserId(user.getUserId());
            //创建时间
            daliyDTO.setCreationTime(new Date());
            //创建人
            daliyDTO.setCreation(user.getUsername());
            //日报效率
            daliyDTO.setExecutioneFficiency(executioneFficiency);
            //星期日打卡记录为1 其他为0
            if (weekStr.equals("星期日")) {
                daliyDTO.setIfWeekday(1);
            } else {
                daliyDTO.setIfWeekday(0);
            }

            //低于百分百之90的才是必填 防止报错
            if (StringUtils.isNotEmpty(reasonsforeFficiencyFailure)) {
                //效率不及格的原因
                daliyDTO.setReasonsforeFficiencyFailure(reasonsforeFficiencyFailure);
            }
            //拆分及格率  方便查询及格跟不及格
            String[] split = executioneFficiency.split("%");
            //百分比
            daliyDTO.setPercent(Integer.valueOf(split[0]));
            //月份
            daliyDTO.setMonth(new Date().getMonth() + 1);
            //几号
            daliyDTO.setMark(new Date().getDate());
            //标记
            //判断是否为最新的 如果如等于于0 表示今天没有存新的数据存新的数据
            if (count == 0) {
                //第一条数据做标记其他为1 方便统计
                if (i == 0) {
                    daliyDTO.setIfSign(0);
                } else {
                    daliyDTO.setIfSign(1);
                }

                //不等于表示已经存在了数据
            } else {
                daliyDTO.setIfSign(1);
            }
            BeanUtils.copyProperties(daliyDTO, daliy);
            daliyArrayList.add(daliy);
        }
        //批量存入数据
        int i = daliyMapper.insertList(daliyArrayList);
        return i == 0 ? false : true;
    }

    /**
     * 日报信息的分页
     *
     * @param daliyDTO 搜索的信息
     * @param request  请求
     * @return
     */
    @Override
    public List<DaliyDTO> findDailyWithDept(DaliyDTO daliyDTO, QueryRequest request) {
        //根据前面的数据联表查询sql
        List<DaliyDTO> daliyDTOList = this.daliyMapper.findDaliyWithDept(daliyDTO);
        return daliyDTOList;
    }

    /**
     * 数据隔离和搜索的数据
     *
     * @param daliyDTO 搜索的信息
     * @return
     */
    @Override
    public DaliyDTO dailyWithDept(DaliyDTO daliyDTO) {
        //数据分离 说明 测试人员 和测试工程师 只能看到自己数据 组长只能看到自己部门的全部信息 经理可以看全部部门信息
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //获取账号部门和角色
        User daliyMessage = userMapper.findUserProfile(user);
        //用户id
        daliyDTO.setUserId(user.getUserId());
        //根据角色id取到日报信息 测试人员和测试工程师 只能看到自己的数据做标记
        if (daliyMessage.getRoleName().equals(UserRoselEnum.TEST_CONTROLER.getMsg()) || daliyMessage.getRoleName().equals(UserRoselEnum.PROJECT_CONTROLER.getMsg())) {
            //只能看自己数据
            daliyDTO.setIfUserRole(1);

            //只能看到自己部门和全部 组长
        } else if (daliyMessage.getRoleName().equals(UserRoselEnum.GROUP.getMsg())) {
            //说明 组长比较特别  部门还有一个测试组长 这个部门表示可以看全部数据
            //判断部门是不是测试组长如果是的话可以看全部的数据
            if (!daliyMessage.getDeptName().equals("测试组长")) {
                daliyDTO.setIfUserRole(2);
                //权限部门名称
                daliyDTO.setJurisDeptName(daliyMessage.getDeptName());

            }else {
                //sql里面没有查询这个字段3 表示查全部
                daliyDTO.setIfUserRole(3);
            }

            //经理能看到全部的数据
        } else if (daliyMessage.getRoleName().equals(UserRoselEnum.PROJECT_MANAGER.getMsg()) || daliyMessage.getRoleName().equals(UserRoselEnum.TEST_MANAGER.getMsg())) {
            //sql里面没有查询这个字段3 表示查全部
            daliyDTO.setIfUserRole(3);

            //没有权限的话就只能看自己
        } else {
            //只能看自己数据
            daliyDTO.setIfUserRole(1);
        }
        return daliyDTO;
    }

    /**
     * 日报的导出excel
     *
     * @param daliyDTO 搜素的数据
     * @return
     */
    @Override
    public List<DaliyDTO> dailyShowExcel(DaliyDTO daliyDTO) {
        //获取权限的数据
        DaliyDTO daliy = dailyWithDept(daliyDTO);
        //根据前面的数据联表查询sql
        List<DaliyDTO> daliyDTOList = this.daliyMapper.findDaliyWithDept(daliy);
        return daliyDTOList;
    }

    /**
     * 删除日报
     *
     * @param id 根据id删除
     */
    @Override
    public int deleteDailyShow(String id) {
        //把数组转成集合
        List<String> list = Arrays.asList(id.split(","));
        //批量删除
        int states = this.batchDelete(list, "id", Daliy.class);
        //删除状态
        return states;
    }

    /**
     * 修改日报
     *
     * @param daliy 修改日报信息
     * @return
     */
    @Override
    @Transactional
    public int updateDaliy(Daliy daliy) {
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //更新时间
        daliy.setUpdaterTime(new Date());
        //更新人
        daliy.setUpdater(user.getUsername());
        //修改日报
        int states = this.updateNotNull(daliy);
        return states;
    }

    /**
     * 判断日报是否添加
     *
     * @param daliyDTO 用户信息
     * @return
     */
    @Override
    public Boolean ifDaliy(DaliyDTO daliyDTO) {
        //先根据用户名称 查取当天的日期查询
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //说明 用 用户 年 月 号 查询当天是否添加过数据
        //日期
        Calendar cal = Calendar.getInstance();
        //年
        int yes = cal.get(Calendar.YEAR);
        //月
        int month = cal.get(Calendar.MONTH) + 1;
        //号
        int date = cal.get(Calendar.DATE);
        //用户id
        Long userId = user.getUserId();
        //SQL构造器
        Example example = new Example(Daliy.class);
        Example.Criteria criteria = example.createCriteria();
        //用户id
        criteria.andEqualTo("userId", userId);
        //年
        criteria.andEqualTo("year", yes);
        //月
        criteria.andEqualTo("month", month);
        //号
        criteria.andEqualTo("mark", date);
        //0的话表示没有添加
        int count = daliyMapper.selectCountByExample(example);
        //状态
        Boolean state = false;
        //大于0说明表示今天添加数据了
        if (count > 0) {
            state = true;
        }
        return state;
    }

    /**
     * 校验日期是否填过日报
     *
     * @param supplementDate 校验日期
     * @return
     */
    @Override
    public Boolean ifSupplement(String supplementDate) {
        //先根据用户名称 查取用户录入的日期查询
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //分割日期 前端传过来的 2020-10-30
        String[] split = supplementDate.split("-");
        //年
        int yes = Integer.valueOf(split[0]);
        //月
        int month = Integer.valueOf(split[1]);
        //号
        int date = Integer.valueOf(split[2]);
        //用户id
        Long userId = user.getUserId();
        //SQL构造器
        Example example = new Example(Daliy.class);
        Example.Criteria criteria = example.createCriteria();
        //用户id
        criteria.andEqualTo("userId", userId);
        //年
        criteria.andEqualTo("year", yes);
        //月
        criteria.andEqualTo("month", month);
        //号
        criteria.andEqualTo("mark", date);
        //0的话表示没有添加
        int count = daliyMapper.selectCountByExample(example);
        //状态
        Boolean state = false;
        //大于0说明表示今天添加数据了
        if (count > 0) {
            state = true;
        }
        return state;
    }

    /**
     * 补录日报
     *
     * @param daliyList                   添加的日报 数组
     * @param executioneFficiency         效率
     * @param reasonsforeFficiencyFailure 效率不及格原因
     * @param supplementDate              补录日期
     * @return
     */
    @Override
    public Boolean supplementAdd(List<DaliyDTO> daliyList, String executioneFficiency, String reasonsforeFficiencyFailure, String supplementDate) throws ParseException {
        //日期
        Calendar cal = Calendar.getInstance();
        //当前用户信息
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        //先判断 根据当前user id 和 当前月份当月的几号 判断当天是否添加过日报
        //补录日报日期
        String[] supplementDateTime = supplementDate.split("-");
        //sql构造器
        Example example = new Example(Daliy.class);
        Example.Criteria criteria = example.createCriteria();
        //月份
        int month = Integer.valueOf(supplementDateTime[1]);
        //几号
        int date = Integer.valueOf(supplementDateTime[2]);
        //年
        int year = Integer.valueOf(supplementDateTime[0]);
        //字符串转为日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateTime = sdf.parse(supplementDate);
        //获取当天是星期几
        String weekStr = getWeekStr(dateTime);
        //用户id
        criteria.andEqualTo("userId", user.getUserId());
        //年
        criteria.andEqualTo("year", year);
        //月份
        criteria.andEqualTo("month", month);
        //几号
        criteria.andEqualTo("mark", date);
        int count = daliyMapper.selectCountByExample(example);
        //给对象批量转换
        ArrayList<Daliy> daliyArrayList = new ArrayList<>();
        //日报对象
        Daliy daliy = new Daliy();
        //日报dto对象
        DaliyDTO daliyDTO = new DaliyDTO();

        for (int i = 0; i < daliyList.size(); i++) {
            daliyDTO = daliyList.get(i);
            daliy = new Daliy();
            //年份
            daliyDTO.setYear(year);
            //用户id
            daliyDTO.setUserId(user.getUserId());
            //创建时间
            daliyDTO.setCreationTime(new Date());
            //创建人
            daliyDTO.setCreation(user.getUsername());
            //日报效率
            daliyDTO.setExecutioneFficiency(executioneFficiency);
            //星期日打卡记录为1 其他为0
            if (weekStr.equals("星期日")) {
                daliyDTO.setIfWeekday(1);
            } else {
                daliyDTO.setIfWeekday(0);
            }

            //低于百分百之90的才是必填 防止报错
            if (StringUtils.isNotEmpty(reasonsforeFficiencyFailure)) {
                //效率不及格的原因
                daliyDTO.setReasonsforeFficiencyFailure(reasonsforeFficiencyFailure);
            }
            //拆分及格率  方便查询及格跟不及格
            String[] split = executioneFficiency.split("%");
            //百分比
            daliyDTO.setPercent(Integer.valueOf(split[0]));
            //月份
            daliyDTO.setMonth(month);
            //几号
            daliyDTO.setMark(date);
            //标记
            //判断是否为最新的 如果如等于于0 表示今天没有存新的数据存新的数据
            if (count == 0) {
                //第一条数据做标记其他为1 方便统计
                if (i == 0) {
                    daliyDTO.setIfSign(0);
                } else {
                    daliyDTO.setIfSign(1);
                }

                //不等于表示已经存在了数据
            } else {
                daliyDTO.setIfSign(1);
            }
            BeanUtils.copyProperties(daliyDTO, daliy);
            daliyArrayList.add(daliy);
        }
        //批量存入数据
        int i = daliyMapper.insertList(daliyArrayList);
        return i == 0 ? false : true;
    }

    /**
     * 当天有多少个星期天
     *
     * @return
     */
    private int weekday() {
        // 返回当月星期天数
        int sundays = 0;
        //一定要EEEE
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        Calendar setDate = Calendar.getInstance();
        // 从第一天开始 到几天是几号
        int day;
        for (day = 1; day <= new Date().getDate(); day++) {
            setDate.set(Calendar.DATE, day);
            String str = sdf.format(setDate.getTime());
            if (str.equals("星期日")) {
                sundays++;
            }
        }
        return sundays;
    }

    /**
     * 获取每月星期日有多少天
     *
     * @return
     */
    private int weekDays() {
        // 返回当月星期天数
        int sundays = 0;
        //一定要EEEE
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        Calendar setDate = Calendar.getInstance();
        // 从第一天开始
        int day;
        for (day = 1; day <= getDaysOfTheMonth(new Date()); day++) {
            setDate.set(Calendar.DATE, day);
            String str = sdf.format(setDate.getTime());
            if (str.equals("星期日")) {
                sundays++;
            }
        }
        return sundays;
    }


    /**
     * 给出你要的月份
     *
     * @param date 当天时间
     * @return
     */
    private int getDaysOfTheMonth(Date date) {
        Calendar rightNow = Calendar.getInstance();
        // 要计算你想要的月份，改变这里即可
        rightNow.setTime(date);
        int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
        return days;
    }

    /**
     * 获取当天是星期几
     *
     * @param date
     * @return
     */

    public static String getWeekStr(Date date) {
        Calendar cal = Calendar.getInstance();
        if (date != null) {
            cal.setTime(date);
        }
        int week = cal.get(Calendar.DAY_OF_WEEK);
        switch (week) {
            case 1:
                return "星期日";
            case 2:
                return "星期一";
            case 3:
                return "星期二";
            case 4:
                return "星期三";
            case 5:
                return "星期四";
            case 6:
                return "星期五";
            case 7:
                return "星期六";
        }
        return "";
    }


    @Override
    public ChartsModel getChartsModel1() {
        ChartsModel chartsModel = new ChartsModel();
        List<SeriesModel> seriesModels = new ArrayList<>();
        //获取最近七天的部分数据
        List<Daliy> weekData = daliyMapper.getWeekData();
        //获取横坐标日期格式->MM月dd日
        chartsModel.setCategory(getDaysBetwwen(ONE_WEEK));
        List<String> collect = weekData.stream().map(X -> X.getProjectNo()).distinct().collect(Collectors.toList());
        //获取所有的项目
        List<String> legend = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(collect)) {
            for (String s : collect) {
                String s1 = s.concat("计划投入");
                String s2 = s.concat("实际投入");
                legend.add(s1);
                legend.add(s2);
            }

            chartsModel.setLegend(legend);
            //获取最近七天的日
            List day = getDay(ONE_WEEK);
            if (CollectionUtils.isNotEmpty(legend)) {
                for (int a = 0; a < legend.size(); a++) {
                    SeriesModel model = new SeriesModel();
                    List data = new ArrayList<>();
                    if (StringUtils.isNotEmpty(legend.get(a)) && legend.get(a).contains("计划投入")) {
                        model.setId(a);
                        model.setName(legend.get(a));
                        List<Daliy> list = daliyMapper.getAllProjectNo(legend.get(a).split("计划投入")[0]);
                        //计算当天的计划投入工时
                        for (int b = 0; b <= ONE_WEEK; b++) {
                            int plannedLaborHours = 0;
                            for (Daliy daliy : list) {
                                if (daliy.getMark() != null && daliy.getMark().toString().equals(day.get(b) + "")) {
                                    plannedLaborHours += daliy.getPlannedLaborHours();
                                }
                            }
                            data.add(plannedLaborHours);
                        }
                    }
                    if (StringUtils.isNotEmpty(legend.get(a)) && legend.get(a).contains("实际投入")) {
                        model.setId(a);
                        model.setName(legend.get(a));
                        List<Daliy> list = daliyMapper.getAllProjectNo(legend.get(a).split("实际投入")[0]);
                        for (int d = 0; d <= ONE_WEEK; d++) {
                            //计算当天的实际投入工时
                            int actuaLinputHours = 0;
                            for (Daliy daliy : list) {
                                if (daliy.getMark() != null && daliy.getMark().toString().equals(day.get(d) + "")) {
                                    actuaLinputHours += daliy.getActuaLinputHours();
                                }
                            }
                            data.add(actuaLinputHours);
                        }
                    }
                    model.setChartData(data);
                    seriesModels.add(model);
                }

            }
            chartsModel.setSeriesModels(seriesModels);
        }
        return chartsModel;
    }

    @Override
    public ChartsModel getChartsModel2() {
        ChartsModel chartsModel = new ChartsModel();
        List<SeriesModel> seriesModels = new ArrayList<>();
        //获取最近七天的部分数据
        List<DaliyVO> weekData = daliyMapper.getWeekDatas();
        //获取横坐标日期格式->MM月dd日
        chartsModel.setCategory(getDaysBetwwen(ONE_WEEK));
        List<String> collect = weekData.stream().map(X -> X.getDeptName()).distinct().collect(Collectors.toList());
        //获取所有的部门
        List<String> legend = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(collect)) {
            for (String s : collect) {
                if (StringUtils.isNotEmpty(s)) {
                    String s1 = s.concat("计划投入");
                    String s2 = s.concat("实际投入");
                    legend.add(s1);
                    legend.add(s2);
                }
            }


            chartsModel.setLegend(legend);
            //获取最近七天的日
            List day = getDay(ONE_WEEK);
            if (CollectionUtils.isNotEmpty(legend)) {
                for (int a = 0; a < legend.size(); a++) {
                    SeriesModel model = new SeriesModel();
                    List data = new ArrayList<>();
                    if (StringUtils.isNotEmpty(legend.get(a)) && legend.get(a).contains("计划投入")) {
                        model.setId(a);
                        model.setName(legend.get(a));
                        List<DaliyVO> list = daliyMapper.getAllDeptName(legend.get(a).split("计划投入")[0]);
                        //计算当天的计划投入工时
                        for (int b = 0; b <= ONE_WEEK; b++) {
                            int plannedLaborHours = 0;
                            for (DaliyVO daliy : list) {
                                if (daliy.getMark() != null && daliy.getMark().toString().equals(day.get(b) + "")) {
                                    plannedLaborHours += daliy.getPlannedLaborHours();
                                }
                            }
                            data.add(plannedLaborHours);
                        }
                    }
                    if (StringUtils.isNotEmpty(legend.get(a)) && legend.get(a).contains("实际投入")) {
                        model.setId(a);
                        model.setName(legend.get(a));
                        List<DaliyVO> list = daliyMapper.getAllDeptName(legend.get(a).split("实际投入")[0]);
                        for (int d = 0; d <= ONE_WEEK; d++) {
                            //计算当天的实际投入工时
                            int actuaLinputHours = 0;
                            for (DaliyVO daliy : list) {
                                if (daliy.getMark() != null && daliy.getMark().toString().equals(day.get(d) + "")) {
                                    actuaLinputHours += daliy.getActuaLinputHours();
                                }
                            }
                            data.add(actuaLinputHours);
                        }
                    }
                    model.setChartData(data);
                    seriesModels.add(model);
                }

            }
            chartsModel.setSeriesModels(seriesModels);
        }

        return chartsModel;
    }

    private static Date getDateAdd(int days) {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -days);
        return c.getTime();
    }

    private static List getDaysBetwwen(int days) {
        List dayss = new ArrayList<>();
        Calendar start = Calendar.getInstance();
        start.setTime(getDateAdd(days));
        Long startTIme = start.getTimeInMillis();
        Calendar end = Calendar.getInstance();
        end.setTime(new Date());
        Long endTime = end.getTimeInMillis();
        Long oneDay = 1000 * 60 * 60 * 24l;
        Long time = startTIme;
        while (time <= endTime) {
            Date d = new Date(time);
            DateFormat df = new SimpleDateFormat("MM月dd日");
            System.out.println(df.format(d));
            dayss.add(df.format(d));
            time += oneDay;
        }
        return dayss;
    }

    private static List getDay(int days) {
        List dayss = new ArrayList<>();
        Calendar start = Calendar.getInstance();
        start.setTime(getDateAdd(days));
        Long startTIme = start.getTimeInMillis();
        Calendar end = Calendar.getInstance();
        end.setTime(new Date());
        Long endTime = end.getTimeInMillis();
        Long oneDay = 1000 * 60 * 60 * 24l;
        Long time = startTIme;
        while (time <= endTime) {
            Date d = new Date(time);
            DateFormat df = new SimpleDateFormat("dd");
            System.out.println(df.format(d));
            dayss.add(df.format(d));
            time += oneDay;
        }
        return dayss;
    }
}
